package com.example.demo.Configurations;

import com.example.demo.Util.AdminInterceptor;
import com.example.demo.Util.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

//import省略
@Configuration
public class SessionConfiguration implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private AdminInterceptor adminInterceptor;

    /**
     * 静态资源处理
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

    /**
     * 注册自定义的拦截器loginInterceptor
     */

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> login_free_patterns = new ArrayList();
        login_free_patterns.add("/api/register");
        login_free_patterns.add("/api/login");
        login_free_patterns.add("/api/send_email");
        login_free_patterns.add("/api/find_change_password");
        login_free_patterns.add("/api/apply_unlock");
        login_free_patterns.add("/api/visiter/**");

        List<String> admin_free_patterns = new ArrayList();


        //registry.addInterceptor(loginInterceptor).addPathPatterns("/api/**").excludePathPatterns(login_free_patterns);
        //registry.addInterceptor(adminInterceptor).addPathPatterns("/api/admin/**").excludePathPatterns();

    }



}
